package org.example.test1;

import java.util.Scanner;

public class Game {
    Person person;
    Computer computer;
    //初始化游戏角色的方法
    public void unit(){
        person = new Person();
        computer = new Computer();
    }
    //游戏方法
    public void startGame(){
        unit();
        System.out.println("*********************************");
        System.out.println("***** 欢迎进入人机游戏  ************");
        System.out.println("*********************************");
        Scanner input = new Scanner(System.in);
        //为两个角色赋值名字
        System.out.println("请输入你的名字: ");
        person.name = input.next();
        System.out.println("请输入计算机的名字: ");
        computer.name = input.next();
        System.out.println("开始对战!");
        char an;
        //人机无限次pk,加分
        do{int perFist = person.showFist();
        int comFist = computer.showFist();
        //比较结果
        if (perFist == comFist){
            System.out.println("平局");
        } else if (perFist == 1 && comFist == 3 || perFist == 2 && comFist == 1 ||
        perFist == 3 && comFist == 2) {
            System.out.println("恭喜"+person.name+"赢了");
        }else {
            System.out.println("恭喜"+computer.name+"赢了");
            computer.score ++;
        }
            System.out.println("是否pk下一轮:");
        an = input.next().charAt(0);
        }while (an == 'y');
        showResult();
    }
    public void showResult(){
        System.out.println(person.name+"\t"+computer.name);
        System.out.println(person.score+"\t"+computer.score);
        if (person.score > computer.score){
            System.out.println(person.name +"赢了!!!");
        } else if (person.score == computer.score) {
            System.out.println("平局");
        }else System.out.println(computer.name+"赢了!!!");
    }
}
